﻿//-----------------------------------------------------------------------
// <copyright file="Orders.cs" company="Craig Longford (deltawolf7@gmail.com)">
//     Copyright (c) Craig Longford. All rights reserved.
// </copyright>
//-----------------------------------------------------------------------

namespace Delta.Mercury.Business.Commerce
{
    using System;
    using System.Collections.Generic;
    using Delta.Data.DataExpress;
    using Delta.Mercury.Business.User;

    /// <summary>
    /// Collection of orders
    /// </summary>
    [Serializable]
    public class Orders : List<Order>
    {
        #region Constructors
        /// <summary>
        /// Initializes a new instance of the Orders class
        /// </summary>
        public Orders()
        {
        }
        #endregion

        #region Load Orders By Date Range
        /// <summary>
        /// Load orders by date range
        /// </summary>
        /// <param name="from">From datetime</param>
        /// <param name="to">To datetime</param>
        /// <param name="showDeleted">Show deleted</param>
        /// <returns>Collection of orders</returns>
        public static Orders Load(DateTime from, DateTime to, bool showDeleted)
        {
            Parameters parameters = new Parameters();
            parameters.Add(new Parameter("From", from.Date));
            parameters.Add(new Parameter("To", to.Date));
            parameters.Add(new Parameter("Deleted", showDeleted));
            return DataAccess.GetCollection<Orders, Order>("LoadOrders", System.Data.CommandType.StoredProcedure, parameters);
        }
        #endregion

        #region Load Orders By Status
        /// <summary>
        /// Load orders by status
        /// </summary>
        /// <param name="status">Order status</param>
        /// <param name="showDeleted">Show deleted</param>
        /// <returns>Collection of orders</returns>
        public static Orders Load(OrderStatus status, bool showDeleted)
        {
            Parameters parameters = new Parameters();
            parameters.Add(new Parameter("OrderStatus", status.Guid));
            parameters.Add(new Parameter("Deleted", showDeleted));
            return DataAccess.GetCollection<Orders, Order>("LoadOrders", System.Data.CommandType.StoredProcedure, parameters);
        }
        #endregion

        #region Load Orders By Owner
        /// <summary>
        /// Load orders by owner
        /// </summary>
        /// <param name="user">Order owner</param>
        /// <param name="showDeleted">Show deleted</param>
        /// <returns>Collection of orders</returns>
        public static Orders Load(IUser user, bool showDeleted)
        {
            Parameters parameters = new Parameters();
            parameters.Add(new Parameter("User", user.Guid));
            parameters.Add(new Parameter("Deleted", showDeleted));
            return DataAccess.GetCollection<Orders, Order>("LoadOrders", System.Data.CommandType.StoredProcedure, parameters);
        }
        #endregion

        #region Search Orders Method
        /// <summary>
        /// Search orders
        /// </summary>
        /// <param name="query">Query to search by</param>
        /// <param name="showDeleted">Show dleteed</param>
        /// <returns>Collection of orders</returns>
        public static Orders Search(string query, bool showDeleted)
        {
            Parameters parameters = new Parameters();
            parameters.Add(new Parameter("Query", query));
            parameters.Add(new Parameter("Deleted", showDeleted));
            return DataAccess.GetCollection<Orders, Order>("SearchOrders", System.Data.CommandType.StoredProcedure, parameters);
        }
        #endregion
    }
}
